<template>
  <div class="model-form">
    <el-page-header @back="goBack" content="更新">
    </el-page-header>
    <QueryForm   v-model="form" mode="edit"
                 @submit="handleSubmit"
                 @cancel="goBack"
                 @staging="handleStaging"
                 ref="ruleForm"></QueryForm>
  </div>

</template>

<script setup>

import QueryForm from "./form.vue";
import {useUpdate} from "@/uses/useUpdate.js";
import {ref} from "vue";

const ruleForm = ref(null);

const form = ref({
  id: '',
  name: '',
  content: '',
  type: '',
  note: '',
  className: null,
  queryType: null,
  permission: null,
  extData: {
    filters: [],
    fields: [],
    params: [],
    sortNames: []
  }
})

const {updateData, goBack,updateStaging} = useUpdate("queryTemplate", form, null, () => {
  if (!form.value.extData) {
    form.value.extData = {};
  }
  if (!form.value.extData.filters) {
    form.value.extData.filters = [];
  }
  if (!form.value.sqlBatchObject) {
    form.value.sqlBatchObject = {};
  }
  if (!form.value.resultHandle) {
    form.value.resultHandle = {};
  }
  if (!form.value.resultHandle.resultHandleObjects) {
    form.value.resultHandle.resultHandleObjects = [];
  }

  const obj = {}
  form.value.extData.filters.forEach((item) => {
    obj[item.javaName] = null;
  })

})
const handleSubmit = (formData) => {
  //form.value = formData;
  updateData();
};

const handleStaging = (formData) => {
  //form.value = formData;
  console.log("handleStaging", formData)
  updateStaging();
};


</script>

<style scoped>

</style>
